#include <bits/stdc++.h>
#define ls (x << 1)
#define rs (x << 1 | 1)
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 5e5 + 10;
int n, q, root;
int h[N], e[N * 2], ne[N * 2], idx;
int deep[N], f[N][20];
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
void dfs(int x, int fa)
{
    deep[x] = deep[fa] + 1;
    f[x][0] = fa;
    for (int i = 1; (1 << i) <= deep[x]; i++)
        f[x][i] = f[f[x][i - 1]][i - 1];
    for (int i = h[x]; i != -1; i = ne[i])
        if (e[i] != fa) dfs(e[i], x);
}
int LCA(int a, int b)
{
    if (deep[a] < deep[b])  swap(a, b);
    for (int i = 19; i >= 0; i--)
        if (deep[a] - (1 << i) >= deep[b])
            a = f[a][i];
    if (a == b)  return b;
    for (int i = 19; i >= 0; i--)
        if (f[a][i] != f[b][i])
            a = f[a][i], b = f[b][i];
    return f[a][0];
}

void solve()
{
    memset(h, -1, sizeof h);
    cin >> n >> q >> root;
    for (int i = 1, a, b; i < n; i++) {
        cin >> a >> b;
        add(a, b), add(b, a);
    }
    dfs(root, 0);
    while (q--) {
        int a, b;
        cin >> a >> b;
        cout << LCA(a, b) << '\n';
    }
}

int main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    int T = 1;
    // cin>>T;
    for (int i = 1; i <= T; i++) {
        solve();
    }
}